<template>
	<body-wrap>
		<view class="topBox" v-if="detail.userId">
			<view class="imgbox">
				<cm-image v-if="detail._id" :src="detail.userId.selfAvatar || detail.userId.avatar"/>
			</view>
			<view class="top-con">
				<view class="name">
					{{detail.userId.name || detail.userId.nickname}}
					<text class="bzhi">专家</text>
				</view>
				<view class="intro">
					{{detail.userId.company}} | {{detail.userId.industry}} | {{detail.userId.jobs}}
				</view>
				<text class="pfwf">回复时间：{{dateFormat('Y-m-d H:i',detail.createTime)}}</text>
			</view>
		</view>
		<view class="payTipsBox" v-if="detail.price && !isBuy">
			<view class="ptips">查看本回复需要支付：¥<text class="price">{{detail.price}}</text></view>
			<view class="paybtn" @click="goPay">立即支付</view>
		</view>
		<view v-else class="detailCon">
			<view class="zjTab">
				<text class="item" :class="{'selected':active==1}" @click="setTab(1)">回复详情</text>
				<text class="item" :class="{'selected':active==2}" @click="setTab(2)">附件</text>
			</view>
			<view class="content">
				<view v-if="active==1" class="replyDetai">
					{{detail.content}}
				</view>
				<view v-else-if="active==2" class="replyDetai">
					<template v-if="detail.annex.length>0">
						附件
					</template>
					<template v-else>
						<empty title="无附件"/>
					</template>
				</view>
			</view>
		</view>
	</body-wrap>
</template>

<script>
	import {defineComponent,reactive,toRefs,onMounted,getCurrentInstance,computed} from 'vue'
	import {onLoad,onShow} from '@dcloudio/uni-app'
	import { useStore } from 'vuex'
	import bodyWrap from "@/components/bodyWrap/index.vue"
	import cmImage from "@/components/cmImage/index.vue"
	import {getCommentDetail,getOrderList} from "@/api/consult.js"
	import {toast,dateFormat} from "@/utils/common.js"
	import empty from "@/components/empty/index.vue"
	export default defineComponent({
		components:{
			bodyWrap,
			cmImage,
			empty
		},
		props:{
		
		},
		setup(props,context) {
			const store = useStore()
			const {proxy} = getCurrentInstance()
			
			const state = reactive({
				userInfo:computed(()=>store.state.base.userInfo),
				backUrl:computed(()=>store.state.base.backUrl),
				active:1,
				cid:'', // 评论id
				detail:'',  
				isBuy:false  // 是否购买
			})
			
			onLoad(async (options)=>{
				if(options && options.id){
					state.cid = options.id
				}
				const res = await getCommentDetail(state.cid)
				if(res.code == 200){
					state.detail = res.data
					// 查看是否支付
					get_order_list()
				}
			})
			
			onMounted( async ()=>{
				store.commit('base/init_orderInfo',{})
			})
			
			const get_order_list = ()=>{
				getOrderList({
					userId:state.userInfo._id,
					productId:state.detail._id,
					status:1
				}).then(res =>{
					if(res.code == 200 && res.data.data.length>0){
						state.isBuy = true
					}
				})
			}
			
			const setTab = num=>{
				state.active = num
			}
			
			const goPay =()=>{
				const pages = getCurrentPages();
				const currentPage = pages[pages.length - 1];
				const fullPath = currentPage.$page.fullPath
				store.commit('base/set_backUrl',currentPage.$page.fullPath)
				const orderinfo = {
					productId:state.detail._id, // 商品id
					orderType:60, // 购买专家回复
					product:state.detail, // 购买的产品信息
					price:state.detail.price,// 商品价格
					name:`${state.detail.userId.name}专家的回复`,// 商品名称
					sellerId: state.detail.userId._id // 卖家id
				}
				store.commit('base/set_orderInfo',orderinfo)
				uni.navigateTo({
					url:'/pages/order/order'
				})
			}
			
			return {
				...toRefs(state),
				setTab,
				dateFormat,
				goPay
			}
		}
	})
</script>

<style lang="scss" scoped>
	.topBox{
		display: flex;
		margin: 0;
		padding:40rpx 20rpx 60rpx 20rpx;
		background-color: #fff;
		.imgbox{
			width: 140rpx;
			height: 140rpx;
			border-radius: 50%;
			overflow: hidden;
			flex-shrink: 0;
		}
		.top-con{
			padding: 0 0 0 20rpx;
			flex-shrink: 0;
			height: 0;
			line-height: normal;
			.name{
				display: flex;
				height: 50rpx;
				align-items: center;
				font-size: 34rpx;
				font-weight: bold;
				padding: 0;
				margin: 0;
				.bzhi{
					display:flex;
					align-items: center;
					background-color: #ff1120;
					font-size: 26rpx;
					color: #fff;
					padding: 0 8rpx;
					border-radius: 5rpx;
					margin: 0 0 0 10rpx;
					height: 40rpx;
				}
				.guanzhu{
					font-size: 26rpx;
					color: #e3af2f;
					border: 1px solid #e3af2f;
					margin: 0 0 0 20rpx;
					padding: 5rpx 15rpx;
					border-radius: 5rpx;
				}
			}
			.intro{
				color: #999;
				font-size: 30rpx;
				height: 50rpx;
				line-height: 50rpx;
				width: 100%;
				white-space: nowrap;
				text-overflow: ellipsis;
				overflow: hidden;
				word-break: break-all;
				padding: 0;
			}
			.pfwf{
				color: #999;
				font-size: 30rpx;
				.num{
					font-weight: bold;
					color: #ff1120;
				}
			}
		}
	}
	.detailCon{
		margin: 0;
		.zjTab{
			display: flex;
			height: 90rpx;
			align-items: center;
			font-size: 34rpx;
			border-bottom: 1px solid #f3f3f3;
			.item{
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: center;
				position: relative;
				z-index: 10;
				height: 100%;
				&.selected{
					color: #e3af2f;
					&::after{
						content: '';
						position: absolute;
						z-index: 10;
						left: 0;
						bottom: 0;
						width: 100%;
						height: 1px;
						background-color: #e3af2f;
					}
				}
			}
		}
		.content{
			padding: 20rpx;
			background-color: #fff;
			min-height: 1000rpx;
			.replyDetai{
				font-size: 28rpx;
				line-height: 48rpx;
			}
		}
	}
	.ftBtnBox{
		display: flex;
		padding: 20rpx 0;
		.ibtn{
			flex: 1;
			padding: 0 15rpx;
		}
	}
	.ylfs{
		background-color: #e3af2f;
		height: 200rpx;
		margin:0 30rpx 10rpx 30rpx;
		border-radius: 20rpx;
		.yltype{
			display: flex;
			align-items: center;
			height: 80rpx;
			padding: 0 30rpx;
			font-size: 30rpx;
			color: #fff;
		}
	}
	.payTipsBox{
		.ptips{
			font-size: 30rpx;
			padding: 100rpx 0;
			text-align: center;
			.price{
				font-size: 40rpx;
				font-weight: bold;
				color: #ff1120;
				padding: 0 0 0 4rpx;
			}
		}
		.paybtn{
			display: flex;
			align-items: center;
			justify-content: center;
			height: 80rpx;
			width: 260rpx;
			border-radius: 40rpx;
			background: #e3af2f;
			font-size: 30rpx;
			color: #fff;
			margin: 0 auto;
			
		}
	}
</style>
